<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改页面</title>
</head>
<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
<script type="text/javascript" src="../res/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="../res/layui/layui.js"></script>
<script type="text/javascript" src="../res/js/Tools.js"></script>
<script type="text/javascript">
    $.ajaxSetup({
        async:false
    });
</script>
<body>
<div id="Beboos">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>领导信息管理</legend>
    </fieldset>
    <form id="form" class="layui-form">
        <!-- 用户ID -->
        <div style="display: none">
            <label class="layui-form-label">用户ID</label>
            <div>
                <input type="text" name="usId" id="usId"  placeholder="用户ID" class="layui-input">
            </div>
        </div>
        <!-- 教练ID -->
        <div  style="display: none">
            <label class="layui-form-label">领导ID</label>
            <div>
                <input type="text" name="leaderId" id="leaderId"  placeholder="教练ID" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 用户名 -->
            <div  class="layui-inline" >
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="leaderName" lay-verify="required" id="leaderName"  placeholder="姓氏名称" class="layui-input">
                </div>
            </div>
            <!-- 登陆账号 -->
            <div class="layui-inline">
                <label class="layui-form-label">登陆账号</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="usName"   id="usName"  placeholder="登陆账号" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 用户电话 -->
            <div  class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="phone" id="phone" lay-verify="required"  placeholder="联系电话" class="layui-input">
                </div>
            </div>
            <!-- 登陆密码 -->
            <div class="layui-inline">
                <label class="layui-form-label">登陆密码</label>
                <div class="layui-input-block whstandard">
                    <input type="password" name="usPass" id="usPass"  placeholder="登陆密码" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!--用户邮箱 -->
            <div  class="layui-inline">
                <label class="layui-form-label">用户邮箱</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="usEmail" id="usEmail" lay-verify="required"  placeholder="用户邮箱" class="layui-input">
                </div>
            </div>
            <!-- 头像 -->
            <div  class="layui-inline">
                <label class="layui-form-label">领导头像</label>
                <div class="layui-input-block whstandard">
                    <button type="button" class="layui-btn" id="test1">
                        <i class="layui-icon">&#xe67c;</i>点击上传图片
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 部门名称 -->
            <div  class="layui-inline">
                <label class="layui-form-label">部门名称</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="deptName" id="deptName"  placeholder="部门名称" class="layui-input">
                </div>
            </div>
            <!-- 岗位名称 -->
            <div  class="layui-inline">
                <label class="layui-form-label">岗位名称</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="postName" id="postName"  placeholder="岗位名称" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <!-- 负责事物 -->
            <div  class="layui-inline">
                <label class="layui-form-label">负责事物</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="leaderBusiness" id="leaderBusiness"  placeholder="擅长项目" class="layui-input">
                </div>
            </div>
            <!-- 通讯地址 -->
            <div  class="layui-inline">
                <label class="layui-form-label">通讯地址</label>
                <div class="layui-input-block whstandard">
                    <input type="text" name="addr" id="addr" lay-verify="required" style="width: 140%" placeholder="通讯地址" class="layui-input">
                </div>
            </div>
        </div>
        <!-- 职责说明 -->
        <div  class="layui-form-item layui-form-text">
            <label class="layui-form-label">职责说明</label>
            <div class="layui-input-block whstandard">
                <input type="text" name="leaderExp" id="leaderExp"  placeholder="职责说明" class="layui-input">
            </div>
        </div>
        <!-- 备注 -->
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">其他说明</label>
            <div class="layui-input-block">
                <textarea name="remark" id="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <!-- 提交 -->
        <div class="layui-input-block">
            <button class="layui-btn"id="btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
    <div id="time" style="display: none">2</div><br>
</div>

    <script type="text/javascript">
        //监听文件上传
        layui.use('upload', function(){
            var upload = layui.upload;
            //参数
            var formData = new FormData(document.getElementById("form"));
            //alert(JSON.stringify(formData));
            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,auto: false //选择文件后不自动上传
                //,bindAction: '#btn' //指向一个按钮触发上传
                ,done: function(res){
                    //上传完毕回调
                    layer.msg(res.msg);
                    //关闭当前层
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                }
                ,error: function(){
                    //alert("文件上传异常");
                }
            });
        });
        //时间选择器
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#creatTime' //指定元素
                ,trigger: 'click'
                ,isInitValue: true //是否填充初始值 是

            });
        });
        var form = null;
        layui.use('form', function(){
            form = layui.form;
            //监听提交按钮
            form.on('submit(formDemo)', function(data){
                //layer.msg("提交了");
                //layer.msg(JSON.stringify(data.field)); //弹出当前表单数据*!/
                var formData = new FormData(document.getElementById("form"));
                var url = "../AtsEmpleader/upLeaderDate";
                $.ajax({
                    type:"post",
                    url:url,
                    data:formData,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        if(obj.msg !=null){
                            layer.msg(obj.msg,{icon:1,time:1000},function(){
                                //关闭当前层
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index);
                            });
                        }
                    }
                });
                return false;
            });
            //调用查询方法
            addByid();
        });

        function addByid(){
            //获取到地址栏的参数id
            var id = getQueryString("id");
            if(id != null){
                $("#usName").attr("disabled",true);//限制账号
                $("#usPass").attr("disabled",true);//限制密码
            }
           // alert("massage");
           $.ajax({
                url:"../AtsEmpleader/findById",
                type:"post",
                data:{
                    id:id
                },
                dataType:"json",
                // contentType: "application/json;charset=utf-8",
                success:function(data){
                    $("#leaderId").val(data.leaderId);
                    $("#usId").val(data.usId);
                    $("#leaderName").val(data.leaderName);
                    //alert(data.deptName+"   "+data.postName);
                    $("#deptName").val(data.deptName);
                    $("#postName").val(data.postName);
                    $("#leaderBusiness").val(data.leaderBusiness);
                    $("#leaderExp").val(data.leaderExp);
                    $("#phone").val(data.phone);
                    $("#addr").val(data.addr);
                    $("#sort").val(data.sort);
                    $("#remark").val(data.remark);

                    $("#usName").val(data.usName);
                    $("#usPass").val(data.usPass);
                    $("#usEmail").val(data.usEmail);


                }
            });
        }

    </script>
</body>
</html>